package com.huawei.appgallery.festivalanimation.particle.initializers;

import com.huawei.appgallery.festivalanimation.particle.Particle;
import com.huawei.appgallery.festivalanimation.particle.utils.RandomUtil;

public class SpeedModuleAndRangeInitializer implements IParticleInitializer {
    private int mMaxAngle;
    private int mMinAngle;
    private float mSpeedMax;
    private float mSpeedMin;

    public SpeedModuleAndRangeInitializer(float f, float f2, int i, int i2) {
        this.mSpeedMin = f;
        this.mSpeedMax = f2;
        this.mMinAngle = i;
        this.mMaxAngle = i2;
        while (this.mMinAngle < 0) {
            this.mMinAngle += 360;
        }
        while (this.mMaxAngle < 0) {
            this.mMaxAngle += 360;
        }
        if (this.mMinAngle > this.mMaxAngle) {
            int i3 = this.mMinAngle;
            this.mMinAngle = this.mMaxAngle;
            this.mMaxAngle = i3;
        }
    }

    public void initParticle(Particle particle) {
        int i;
        float nextFloat = this.mSpeedMin + RandomUtil.nextFloat(this.mSpeedMax - this.mSpeedMin);
        if (this.mMaxAngle == this.mMinAngle) {
            i = this.mMinAngle;
        } else {
            i = RandomUtil.nextInt(this.mMaxAngle - this.mMinAngle) + this.mMinAngle;
        }
        double toRadians = Math.toRadians((double) i);
        particle.mSpeedX = (float) (((double) nextFloat) * Math.cos(toRadians));
        particle.mSpeedY = (float) (Math.sin(toRadians) * ((double) nextFloat));
        particle.mInitialRotation = (float) (i - 90);
    }
}
